package net.form.processing;

import java.awt.Color;
import java.util.ArrayList;
import java.util.List;

public class ClusterList {

	protected int id;

	protected int color;
	List<Cluster> value = new ArrayList<Cluster>();

	public ClusterList(int id, List<Cluster> value) {
		super();
		this.id = id;
		addValue(value);
	}

	int getId() {
		return id;
	}

	public void clear() {
	}

	public List<Cluster> getValue() {
		return value;
	}

	public void addValue(List<Cluster> clusters) {
		for (Cluster c : clusters) {
			if (value.contains(c)) {
				int index = value.indexOf(c);
				Cluster c2 = value.get(index);
				c2.addValue(c.getValue());
			} else {
				value.add(c);
			}
		}

	}

	public void removeValue(List<Cluster> clusters) {
		for (Cluster c : clusters) {
			if (value.contains(c)) {
				int index = value.indexOf(c);
				Cluster c2 = value.get(index);
				c2.removeValue(c.getValue());
			}
		}
	}

	public double distance(List<Cluster> clusters) {
		double distance = 0;
		for (Cluster c : clusters) {
			if (value.contains(c)) {
				int index = value.indexOf(c);
				Cluster c2 = value.get(index);
				distance += c2.distance(c.getValue());
			}
		}
		return distance;
	}

	public int getColor() {
		return getColor(id);
	}

	public int getColor(int id) {
		int color = 0;
		switch (id + 1) {
		case 1:
			color = Color.red.getRGB();
			break;
		case 2:
			color = Color.blue.getRGB();
			break;
		case 3:
			color = Color.green.getRGB();
			break;
		case 4:
			color = Color.yellow.getRGB();
			break;
		case 5:
			color = Color.pink.getRGB();
			break;
		case 6:
			color = Color.cyan.getRGB();
			break;
		case 7:
			color = Color.magenta.getRGB();
			break;
		case 8:
			color = Color.black.getRGB();
			break;
		case 9:
			color = Color.gray.getRGB();
			break;
		case 10:
			color = Color.orange.getRGB();
			break;
		case 11:
			color = Color.white.getRGB();
			break;
		default:
			color = Math.round((id + id + id + id + 10));
			break;
		}
		return color;
	}

	public void setColor(int color) {
		this.color = color;
	}

	public String getType() {
		return "Cluster compuesto";
	}
}
